*-------------------------------------------------------------------------------------------------------------*
* The Causal Effects of R&D Grants: Evidence from a Regression Discontinuity (Santoleri et al., 2020)
*-------------------------------------------------------------------------------------------------------------*

/// Figure 1: Graphical evidence of discontinuity in firm-level outcomes

use $data_path/DATA_ALL_FINAL.dta, clear

* set figure style
set scheme s1mono  
grstyle init newscheme, replace
grstyle set symbolsize 6, pt
grstyle set size 7pt: title
grstyle set size 13pt: subtitle
grstyle set size 11pt: axis_title
grstyle set plain, horizontal nogrid

label var ln_citw_patents_pre_w "Cite-weighted Patents"
label var pe_pre "Private Equity"
label var assets_pre_w "Assets"
label var employees_pre_w "Employees"
label var revenues_pre_w "Revenues"
label var investment_pre_w "Investment"
label var investment_post_w "Investment"
label var age_pre "Age" 

* Figure 1
graph drop _all
foreach var of varlist investment_pre_w ln_citw_patents_pre_w pe_pre assets_pre_w employees_pre_w revenues_pre_w /*age_pre*/ {
cap drop mean_`var'
egen mean_`var' = mean(`var') if phase_smei==2, by(rank)	

twoway  ///
	(lpolyci `var' rank if rank<0 & phase_smei==2 & inrange(rank,-20,10), n(20) deg(2) ker(rec) bwidth(20) fintensity(30)  alw(none) lc(black ..) graphregion(margin(l-4))) || ///
	(lpolyci `var' rank if rank>0 & phase_smei==2 & inrange(rank,-20,10), n(10) deg(2) ker(rec) bwidth(10) fintensity(30)  alw(none) lc(black ..)) || ///
	scatter mean_`var' rank if  phase_smei==2 & inrange(rank,-20,10), xline(0)  legend(off) msize(vsmall) mcolor(black) name(`var'_2, replace) title(`: variable label `var'') ytitle("") xtitle(Centered ranks, size(medsmall) height(3))
}
graph combine investment_pre_w_2 ln_citw_patents_pre_w_2 pe_pre_2 assets_pre_w_2 employees_pre_w_2 revenues_pre_w_2 /*age_pre_2*/, col(3)  name(gr_combine1, replace) xsize(15) ysize(10) iscale(*.8) title(Panel A. Pre-grant, size(small) margin(b=3)) plotregion(margin(-2 -2 -2 -2))
graph export $output/Figure_1a.png, replace width(2200)

label var ln_citw_patents_post_v2 "Cite-weighted Patents"
label var pe_post "Private Equity"
label var assets_2_w "Assets"
label var employees_2_w "Employees"
label var revenues_2_w "Revenues"
label var exit3 "Failure"

* Figure 2
foreach var of varlist investment_post_w ln_citw_patents_post_w pe_post assets_2_w employees_2_w revenues_2_w /*exit3*/ {
cap drop mean_`var'
egen mean_`var' = mean(`var') if phase_smei==2, by(rank)	

twoway  ///
	(lpolyci `var' rank if rank<0 & phase_smei==2 & inrange(rank,-20,10), n(20) deg(2) ker(rec) bwidth(20) fintensity(30)  alw(none) lc(black ..) graphregion(margin(l-4))) || ///
	(lpolyci `var' rank if rank>0 & phase_smei==2 & inrange(rank,-20,10), n(10) deg(2) ker(rec) bwidth(10) fintensity(30)  alw(none) lc(black ..)) || ///
	scatter mean_`var' rank if  phase_smei==2 & inrange(rank,-20,10), xline(0)  legend(off) msize(vsmall) mcolor(black) name(`var'_2, replace) title(`: variable label `var'') ytitle("") xtitle(Centered ranks, size(medsmall) height(3))
}
graph combine investment_post_w_2 ln_citw_patents_post_w_2 pe_post_2 assets_2_w_2 employees_2_w_2 revenues_2_w_2 /*exit3_2*/, col(3) name(gr_combine2, replace) xsize(15) ysize(10) iscale(*.8) title(Panel B. Post-grant, size(small) margin(b=3))  plotregion(margin(-2 -2 -2 -2))
graph export $output/Figure_1b.png, replace width(2200)

graph combine gr_combine1 gr_combine2, col(1)  xsize(10) ysize(12) iscale(*.95) plotregion(margin(-2 -2 -2 -2))
graph export $output/Figure_1.png, replace width(2200)


erase $output/Figure_1a.png
erase $output/Figure_1b.png

erase scheme-newscheme.scheme

